<template>
  <div class="ms-list">
    <el-row class="operation">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">
          <icon name="home"></icon>
        </el-breadcrumb-item>
        <el-breadcrumb-item>渠道推广</el-breadcrumb-item>
        <el-breadcrumb-item>客户问卷</el-breadcrumb-item>
        <el-breadcrumb-item>列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>

    <ms-slide title="问卷调查" :width="800" ref="slideSurvey">
      <el-form class="form" label-width="200px" size="small" :model="row.form" ref="formSurvey">
        <h3>一、企业详情</h3>
        <el-form-item label="项目名称" prop="itemName">
          <el-input disabled v-model="row.form.itemName"></el-input>
        </el-form-item>
        <el-form-item label="公司官方网址" prop="webSite">
          <el-input disabled v-model="row.form.webSite">
            <template slot="prepend">Http://</template>
          </el-input>
        </el-form-item>
        <el-form-item label="公司成立时间" prop="regtime">
          <el-input disabled v-model="row.form.regtime" placeholder="如：2010-12-08"></el-input>
        </el-form-item>
        <el-form-item label="公司旗下品牌" prop="brands">
          <el-input disabled v-model="row.form.brands"></el-input>
        </el-form-item>
        <el-form-item label="该项目已推广" prop="popularizeTimeSpan">
          <el-input disabled v-model="row.form.popularizeTimeSpan" placeholder="多长时间"></el-input>
        </el-form-item>
        <el-form-item label="是否有分公司" prop="filiale">
          <el-radio-group disabled v-model="row.form.filiale">
            <el-radio :label="0">没有</el-radio>
            <el-radio :label="1">有</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="分公司所在城市" prop="filialeCitys">
          <el-input disabled v-model="row.form.filialeCitys" placeholder="多个请以逗号隔开"></el-input>
        </el-form-item>
        <el-form-item label="对外宣传" prop="cooperantShop">
          <el-input disabled v-model="row.form.cooperantShop">
            <template slot="prepend">公司目前有</template>
            <template slot="append">家加盟店</template>
          </el-input>
        </el-form-item>
        <el-form-item label="项目招商团队" prop="teamPeople">
          <el-input disabled v-model="row.form.teamPeople">
            <template slot="prepend">有</template>
            <template slot="append">人</template>
          </el-input>
        </el-form-item>
        <el-form-item label="日最低资源数" prop="dailyMinResource">
          <el-input disabled v-model="row.form.dailyMinResource"></el-input>
        </el-form-item>
        <el-form-item label="是否有完善的在线客服部门" prop="onlineService">
          <el-radio-group disabled v-model="row.form.onlineService">
            <el-radio :label="0">没有</el-radio>
            <el-radio :label="1">有</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="公司目前的来访本分泌大概是" prop="visitingRate">
          <el-input disabled v-model="row.form.visitingRate">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
        <el-form-item label="签单百分比大概是" prop="closeRate">
          <el-input disabled v-model="row.form.closeRate">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
        <h3>二、品牌定位</h3>
        <el-form-item label="项目是做什么的？" prop="productOrientation">
          <el-input disabled v-model="row.form.productOrientation"></el-input>
        </el-form-item>
        <el-form-item label="项目有哪些产品系列？" prop="products">
          <el-input disabled v-model="row.form.products"></el-input>
        </el-form-item>
        <el-form-item label="加盟商的男女比例" prop="genderRation">
          <el-input disabled v-model="row.form.genderRation" placeholder="如：6:4"></el-input>
        </el-form-item>
        <el-form-item label="年龄段主要以" prop="ageSegment">
          <el-input disabled v-model="row.form.ageSegment" placeholder="如：12-20岁，80后，大学生">
            <template slot="append">为主</template>
          </el-input>
        </el-form-item>
        <el-form-item label="核心竞争优势及主要卖点是什么？（比如免加盟费、赠送装修等）" prop="advantage">
          <el-input disabled v-model="row.form.advantage" placeholder="多个请以逗号隔开"></el-input>
        </el-form-item>
        <el-form-item label="正在使用的招商页面地址" prop="joinWebSite">
          <el-input disabled v-model="row.form.joinWebSite">
            <template slot="prepend">http://</template>
          </el-input>
        </el-form-item>
        <el-form-item label="投资金额" prop="minInvestment">
          <el-input disabled v-model="row.form.minInvestment">
            <template slot="prepend">最低</template>
            <template slot="append">元</template>
          </el-input>
          <el-input disabled v-model="row.form.maxInvestment">
            <template slot="prepend">最高</template>
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="更加详细的加盟政策" prop="joinPolicy">
          <el-input disabled v-model="row.form.joinPolicy" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="公司主要的竞争对手有哪些？" prop="competitor">
          <el-input disabled v-model="row.form.competitor" placeholder="多个请以逗号隔开"></el-input>
        </el-form-item>
        <el-form-item label="同行业中，正在使用电视广告或者曾经使用过电视广告的有" prop="tvCompetitor">
          <el-input disabled v-model="row.form.tvCompetitor" placeholder="多个请以逗号隔开"></el-input>
        </el-form-item>
        <h3>三、推广信息</h3>
        <el-form-item label="主要推广关键词" prop="mainKeywords">
          <el-input disabled v-model="row.form.mainKeywords"></el-input>
        </el-form-item>
        <el-form-item label="重点推广地区" prop="vitalArea">
          <el-input disabled v-model="row.form.vitalArea"></el-input>
        </el-form-item>
        <el-form-item label="主要推广区域" prop="mainArea">
          <el-input disabled v-model="row.form.mainArea"></el-input>
        </el-form-item>
        <el-form-item label="禁止推广区域" prop="notArea">
          <el-input disabled v-model="row.form.notArea"></el-input>
        </el-form-item>
        <h3>四、对接信息</h3>
        <el-form-item label="对接人" prop="contacts">
          <el-input disabled v-model="row.form.contacts"></el-input>
        </el-form-item>
        <el-form-item label="联系手机" prop="mobile">
          <el-input disabled v-model="row.form.mobile"></el-input>
        </el-form-item>
        <el-form-item label="联系QQ" prop="qq">
          <el-input disabled v-model="row.form.qq"></el-input>
        </el-form-item>
      </el-form>
    </ms-slide>

    <ms-search :data="search.list" @click="updateConditions"/>

    <el-table
      v-loading="table.loading"
      size="small" stripe border
      :data="table.list"
      :fit="true">
      <el-table-column prop="id" label="ID" min-width="80" fixed></el-table-column>
      <el-table-column prop="itemName" label="项目名称" min-width="200"></el-table-column>
      <el-table-column prop="contacts" label="姓名" min-width="100"></el-table-column>
      <el-table-column prop="mobile" label="手机" min-width="100"></el-table-column>
      <el-table-column prop="qq" label="qq" min-width="100"></el-table-column>
      <el-table-column label="操作" min-width="120" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click.native.prevent="showSurveySlide(scope.$index)">查看</el-button>
          <ms-confirm-button title="删除" @confirm="deleteSurvey(scope.$index)">
            <p>您确定要删除<code>id = {{scope.row.id}}</code>的问卷调查吗？</p>
          </ms-confirm-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      class="pagination"
      layout="total, sizes, prev, pager, next, jumper"
      :current-page.sync="table.pagination.page"
      :total="table.pagination.totalRow"
      :page-size="table.pagination.pageSize"
      :page-sizes="table.pagination.pageSizes"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
  </div>
</template>

<script type="text/ecmascript-6">
  import MsSearch from '@/components/common/Search.vue'
  import MsSlide from '@/components/common/Slide.vue'
  import MsConfirmButton from '@/components/common/ConfirmButton.vue'
  import { SEARCH_CONDITION } from '@/models/customer/platform/survey'
  import Api from '@/api/customer/platform/survey'
  import ResponseParse from '@/utils/response-parse'

  export default {
    components: {
      MsSlide,
      MsSearch,
      MsConfirmButton
    },
    data () {
      return {
        search: {
          list: [],
          condition: {}
        },
        table: {
          loading: true,
          list: [],
          pagination: {}
        },
        row: {
          form: ''
        }
      }
    },
    created () {
      this.search.list = SEARCH_CONDITION
      this.table.list = []
      this.requestList()
    },
    methods: {
      requestList () {
        this.table.loading = true
        const search = Object.assign({}, this.table.pagination, this.search.condition)
        Api.list({search: search}, response => {
          let status = response.status || 0
          let body = response.data || []
          if (status === 200 || status === 204) {
            this.table.list = body
            this.table.pagination = ResponseParse.pagination(response.headers)
//            if (this.table.pagination.totalPage === this.table.pagination.pag) {
//              this.tbHeight = ''
//            } else {
//              this.$set(this, 'tbHeight', this.PHeigh - this.$refs.msSearch.clientHeight)
//            }
          } else {
//            this.tbHeight = ''
            this.table.list = []
            this.$message.error(response.data.error || '数据获取失败')
          }
          this.table.loading = false
        })
      },
      updateConditions (conditions) {
        this.table.pagination.page = 1
        this.search.condition = conditions
        this.requestList()
      },
      handleSizeChange (val) {
        this.table.pagination.pageSize = val
        this.requestList()
      },
      handleCurrentChange (val) {
        this.table.pagination.page = val
        this.requestList()
      },
      showSurveySlide (index) {
        this.row.form = this.table.list[index]
        this.$refs['slideSurvey'].show()
      },
      deleteSurvey (index) {
        Api.delete({id: this.table.list[index].id}, response => {
          let status = response.status || 0
          let body = response.data || []
          if (status >= 200 && status <= 204) {
            this.table.list.splice(index, 1)
            this.$message.success('删除成功')
          } else {
            this.$message.error(body.error || '删除失败')
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
